<?php
/**
 * 系统设置
 * User: ws
 * Date: 2018/7/23
 * Time: 16:35
 */

namespace app\admin\controller;


class Config  extends Init
{
    function _initialize()
    {
        parent::_initialize();
        $this->model = model('config');
    }


    function index(){
        $list = $this->model->get_list('', '', '30', 2);
        foreach ($list['data'] as $rs){
            $config[$rs['name']] = $rs['value'];
        }
        $url = config('aliyun_oss.url');
        $config['attention'] = str_replace("/goods","$url.goods",$config['attention']);
        $config['scraping'] = str_replace("/goods","$url.goods",$config['scraping']);
        $config['treasure'] = str_replace("/goods","$url.goods",$config['treasure']);
        return view('index',['list' => $config]);
    }

    function add(){
        $params = input('param.');
        $params['attention'] = base64_decode($params['attention']);
        $params['scraping'] = base64_decode($params['scraping']);
        $params['treasure'] = base64_decode($params['treasure']);
        $url = config('aliyun_oss.url');
        $params['attention'] = str_replace("$url.goods","/goods",$params['attention']);
        $params['scraping'] = str_replace("$url.goods","/goods",$params['scraping']);
        $params['treasure'] = str_replace("$url.goods","/goods",$params['treasure']);
        $result = $this->model->add($params,$this->model->get_list('', '', '30', 2));
        if($result){
            return json(array('code'=>200,'msg'=>'添加成功'));
        }else{
            return json(array('code'=>0,'msg'=>'添加失败'));
        }
    }
}